package com.tkp.ExceptionHandler;

import com.tkp.entity.HttpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: duk
 * @Date: 2021/11/9 21:05
 * @Description: 全局异常处理_对是否传入toKen拦截处理
 */
@RestControllerAdvice
@Slf4j
public class RuntimeExceptionHandler {

    /**
     * 对RuntimeException异常进行拦截处理
     * @param runtimeException 运行时异常
     * @return 异常信息
     */
    @ExceptionHandler({RuntimeException.class})
    public ResponseEntity<HttpException> runtimeException(RuntimeException runtimeException){
        HttpException httpException = new HttpException();
        String message = runtimeException.getMessage();
        httpException.setMsg(HttpStatus.BAD_REQUEST.value(),message);
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(httpException);
    }
}
